package com.sci.gen.singletable;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import com.jfinal.plugin.activerecord.generator.MetaBuilder;
import com.jfinal.plugin.activerecord.generator.TableMeta;

public class SingleTableMetaBuilder extends MetaBuilder {

	protected String genTableName;
	
	public SingleTableMetaBuilder(DataSource dataSource,String genTableName) {
		super(dataSource);
		this.genTableName = genTableName;
	}
	
	
	protected void buildTableNames(List<TableMeta> ret) throws SQLException {
		ResultSet rs = getTablesResultSet();
		while (rs.next()) {
			String tableName = rs.getString("TABLE_NAME");
			
			if (genTableName.contains(tableName)) {
				System.out.println("Skip table :" + tableName);
				
				
				TableMeta tableMeta = new TableMeta();
				tableMeta.name = tableName;
				tableMeta.remarks = rs.getString("REMARKS");
				
				tableMeta.modelName = buildModelName(tableName);
				tableMeta.baseModelName = buildBaseModelName(tableMeta.modelName);
				ret.add(tableMeta);
				
			}
			
			
		}
		rs.close();
	}

}
